﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Jermaine.Extensions
{

    public static class XElementExtensions
    {
        /// <summary>
        /// 获取属性值
        /// </summary>
        /// <typeparam name="TTarget"></typeparam>
        /// <param name="e"></param>
        /// <param name="attributeName"></param>
        /// <returns></returns>
        public static TTarget GetAttributeValue<TTarget>(this XElement e, string attributeName) {
            var attribute = e.Attribute(attributeName);
            if (attribute == null) {
                return default(TTarget);
            }

            return attribute.Value.Parse<TTarget>();
        }
    }
}
